package com.sky.shortlink.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sky.shortlink.project.convention.result.Result;
import com.sky.shortlink.project.convention.result.Results;
import com.sky.shortlink.project.dto.req.RecycleBinRemoveReqDTO;
import com.sky.shortlink.project.dto.req.RecycleBinSaveReqDTO;
import com.sky.shortlink.project.dto.req.ShortLinkRecycleBinPageReqDTO;
import com.sky.shortlink.project.dto.resp.ShortLinkPageRespDTO;
import com.sky.shortlink.project.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Blue sky
 * @Description 回收站控制层
 * @create 2024-02-29 15:27
 */
@RestController
@RequiredArgsConstructor
@Slf4j
public class RecycleBinController {
    private final RecycleBinService recycleBinService;

    /**
     * 将短链接移至回收站
     */
    @PostMapping("/api/short-link/v1/recycle-bin/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveReqDTO requestPara){
        recycleBinService.saveRecycleBin(requestPara);
        return Results.success();
    }



    /**
     * 分页查询回收站短链接
     */
    @GetMapping("/api/short-link/v1/recycle-bin/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
        return Results.success(recycleBinService.pageShortLink(requestParam));
    }

    /**
     * 恢复回收站里的短链接
     */
    @PostMapping("/api/short-link/v1/recycle-bin/recover")
    public Result<Void> recover(@RequestBody RecycleBinSaveReqDTO requestParam){
        recycleBinService.recover(requestParam);
        return Results.success();
    }

    /**
     * 移除回收站里的短链接
     */
    @PostMapping("/api/short-link/v1/recycle-bin/remove")
    public Result<Void> remove(@RequestBody RecycleBinRemoveReqDTO requestParam){
        recycleBinService.remove(requestParam);
        return Results.success();
    }
}
